<%--
  Created by IntelliJ IDEA.
  User: colick
  Date: 2015/4/20
  Time: 14:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
</head>
<body>
    <div class="col-sm-9">
        <!--输入区域-->
        <div class="widget-box transparent">
            <div class="widget-header widget-header-small">
                <h4 class="widget-title blue smaller">
                    <i class="ace-icon glyphicon glyphicon-file orange"></i>
                    ${operateName}部门 </h4>
            </div>
            <div class="widget-body">
                <div class="widget-main padding-8">
                    <!-- #section:pages/profile.feed -->
                    <div id="profile-feed-1" class="profile-feed">
                        <form id="authDeptEditFrom" class="form-horizontal" role="form">
                            <table width="96%" cellpadding="0" cellspacing="2" id="mytable"
                                   style="border:1PX solid #DCEBF7; background:#ffffff; margin-left:10px">
                                <style>#mytable td {
                                    border-bottom: 1px solid #DCEBF7
                                }</style>
                                <tr>
                                    <td width="150" height="28" align="right" nowrap="nowrap" bgcolor="#EDF3F4">
                                        <strong>机构代码：</strong>
                                        <input name="orgCode" type="hidden" id="orgCode" value="${orgCode}"/>
                                    </td>
                                    <c:if test="${operateType eq 1}">
                                        <td>
                                            <input name="text222" type="text" disabled="disabled" class="col-xs-12" value="${orgName}"/>
                                        </td>
                                    </c:if>
                                    <c:if test="${operateType eq 2}">
                                        <td>
                                            <input name="text222" type="text" disabled="disabled" class="col-xs-12"
                                                   value="${authDept.orgName}"/>
                                        </td>
                                    </c:if>
                                </tr>
                                <tr id="tr3">
                                    <td height="28" align="right" nowrap="nowrap" bgcolor="#EDF3F4"><strong>部门代码：</strong></td>
                                    <c:if test="${operateType eq 1}">
                                        <td>
                                            <input name="deptCode" type="text" id="deptCode" class="col-xs-12"/>
                                        </td>
                                    </c:if>
                                    <c:if test="${operateType eq 2}">
                                        <td>
                                            <input name="deptCodeShow" type="text" id="deptCodeShow" class="col-xs-12"
                                                   value="${authDept.deptCode}" disabled="disabled"/>
                                            <input name="deptId" type="hidden" id="deptId"
                                                   value="${authDept.deptId}"/>
                                            <%--<input name="deptCode" type="hidden" id="deptCode" value="${authDept.deptCode}"/>--%>
                                        </td>
                                    </c:if>
                                </tr>
                                <tr id="tr3">
                                    <td width="150" height="28" align="right" nowrap="nowrap" bgcolor="#EDF3F4">
                                        <strong>部门名称：</strong></td>
                                    <td><input name="deptName" type="text" id="deptName" class="col-xs-12"
                                               value="${authDept.deptName}"/></td>
                                </tr>
                                <tr id="tr2">
                                    <td width="150" height="28" align="right" nowrap="nowrap" bgcolor="#EDF3F4">
                                        <strong>描述：</strong></td>
                                    <td><textarea name="remark" rows="6" class="col-xs-12" id="remark">${authDept.remark}</textarea></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </div>
                <div class="col-xs-12" style="text-align:center"><!-- 按钮行-->
                    <div class="clearfix form-actions" style="">
                        <c:if test="${operateType eq 1}">
                            <button class="btn btn-info" type="button" onclick="submitAuthDeptEditFromForAdd();">
                                <i class="ace-icon fa fa-save bigger-110"></i>
                                保 存
                            </button>
                        </c:if>
                        <c:if test="${operateType eq 2}">
                            <button class="btn btn-info" type="button" onclick="submitAuthDeptEditFromForEdit();">
                                <i class="ace-icon fa fa-save bigger-110"></i>
                                保 存
                            </button>
                        </c:if>
                        <button class="btn" type="button" onclick="history.go(-1)">
                            <i class="ace-icon fa fa-undo bigger-110"></i>
                            返 回
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="${resRoot}/plugin/ace-v1.3/assets/js/jquery.validate.min.js"></script>
    <script src="${resRoot}/plugin/jquery-validation/localization/messages_zh.js"></script>
    <style type="text/css">
        .help-block2 {
            display:block;
            margin-top:5px;
            margin-bottom:10px;
            color:#d16e6c
        }
    </style>
    <script type="text/javascript">
        //提交表单函数新增
        function submitAuthDeptEditFromForAdd() {
            //验证通过后进行保存
            if (validateForm()) {
                $.ajax({
                    url: contextPath + "/auth/authdept/saveAuthDeptForAdd.json",
                    type: "post",
                    //data: $("#authDeptEditFrom").serialize(),
                    data: {
                        orgCode: $("#orgCode").val(),
                        deptCode: $.trim($("#deptCode").val()),
                        deptName: $.trim($("#deptName").val()),
                        remark: $.trim($("#remark").val())
                    },
                    async: false,
                    success: function (data) {
                        var msg = eval("(" + data + ")");
                        $.Alert(msg.message,'',toAuthDeptList);
                    },
                    error: function () {
                        $.Alert('服务异常，请稍后尝试!','',null);
                    }
                });
            }
        }

        //提交表单函数修改
        function submitAuthDeptEditFromForEdit() {
            //验证通过后进行保存
            if (validateForm()) {
                $.ajax({
                    url: contextPath + "/auth/authdept/saveAuthDeptForEdit.json",
                    type: "post",
                    data: {
                        deptId: $("#deptId").val(),
                        deptName: $.trim($("#deptName").val()),
                        remark: $.trim($("#remark").val())
                    },
                    async: false,
                    success: function (data) {
                        var msg = eval("(" + data + ")");
                        $.Alert(msg.message,'',toAuthDeptList);
                    },
                    error: function () {
                        $.Alert('服务异常，请稍后尝试!','',null);
                    }
                });
            }
        }

        //编辑完后返回上个页面
        function toAuthDeptList() {
            location.href = contextPath + "/auth/authdept/toAuthDeptList.htm?orgCode=${orgCode}";
        }

        //表单验证函数
        function validateForm() {
            return $("#authDeptEditFrom").validate({
                errorElement: 'span',
                errorClass: 'help-block2',
                focusInvalid: false,
                rules: {
                    "deptCode": {
                        required: true,
                        maxlength: 20,
                        remote: {
                            url: contextPath + '/auth/authdept/validDeptCode.json',
                            type: "post",
                            async: false,
                            data: {
                                deptCode: function () {
                                    return $.trim($("#deptCode").val());
                                }
                            }
                        }
                    },
                    "deptName": {
                        required: true,
                        maxlength: 48
                    }
                },
                messages: {
                    "deptCode": {
                        remote: "该部门代码已存在,请重新添加!"
                    }
                },

                highlight: function (e) {
                    $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
                },

                success: function (e) {
                    $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                    $(e).remove();
                },

                errorPlacement: function (error, element) {
                    if (element.is(':checkbox') || element.is(':radio')) {
                        var controls = element.closest('div[class*="col-"]');
                        if (controls.find(':checkbox,:radio').length > 1) controls.append(error);
                        else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                    }
                    else if (element.is('.select2')) {
                        error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                    }
                    else if (element.is('.chosen-select')) {
                        error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                    }
                    else if (element.is('textarea')) {
                        error.appendTo(element.parent());
                    }
                    else if (element.is('input[type=text]')) {
                        error.appendTo(element.parent());
                    }
                    else error.insertAfter(element.parent());
                }
            }).form();
        }
    </script>
</body>
</html>
